<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%
	//获取门诊记录
	String cardNo = input.getDesc("cardNo","320222195311220577");
	String patientName = input.getDesc("patientName","任荣保");
	if(cardNo.equals("622223199406074127")){
		cardNo = "320222195311220577";
		patientName = "任荣保";
	}
	List<Map> list = QBuilder.db("basedb").queryHql("select new map(m.patid as patid ,m.hzxm as hzxm ,m.czrq as czrq , m.ghrq as ghrq , m.ksmc as ksmc ,m.ysmc as ysmc ,sf.sfzh as cardNo , m.djzbz as djzbz,m.xh as ghxh  ) from mzjl m , SF_BRXXK sf  where m.patid = sf.patid  and sf.sfzh = '"+cardNo+"' and sf.hzxm = '"+ patientName +"' ");
	
	StringBuffer sb = new StringBuffer();
	sb.append("0");
	for(Map map : list){
		String date =map.get("ghrq").toString();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhh:mm:ss");
		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		map.put("ghrq",sdf1.format(sdf.parse(date)));
		sb.append(",");
		sb.append(map.get("ghxh").toString());
	}
	//诊断结果库
	List<Map> zdList =QBuilder.db("basedb").queryHql("select new map(ghxh as ghxh , zdmc as zdmc) from mzzd where ghxh in("+sb.toString()+")");
	Map zdMap = new HashMap();
	for(Map map : zdList){
		zdMap.put(map.get("ghxh"),map.get("zdmc"));
	}
	List<Map> cflist = QBuilder.db("basedb").queryHql("select new map(mf.ypmc as ypmc , mf.ypgg as ypgg , mf.ypdw as ypdw ,mf.ypsl as ypsl , mf.ypfj as ypfj , mf.ylsj as ylsj , m.ghxh as ghxh) from mzcfmx  mf , mzcf m where m.xh = mf.cfxh and m.jlzt = 0 and m.ghxh in("+sb.toString()+")");
	
	//费用明细集合
	List<Map> feelist = QBuilder.db("basedb").queryHql("select new map( js.sfrq as sfrq , m.jssjh as jssjh ,m.dxmmc as dxmmc , m.xmje as xmje,js.ghxh as ghxh) from SF_BRJSMXK m , SF_BRJSK js where m.jssjh = js.sjh and js.jlzt = 0 and js.ghxh in("+sb.toString() + ")");
	double money = 0;
	Map moneyMap = new HashMap();
	for(Map map : cflist){
		double num = Double.parseDouble(map.get("ypsl").toString());
		double price = Double.parseDouble(map.get("ylsj").toString());
		double tempMoney = moneyMap.get(map.get("ghxh").toString()) == null ? 0 : Double.parseDouble(moneyMap.get(map.get("ghxh").toString()).toString());
	
		tempMoney += (num * price);
		
		moneyMap.put(map.get("ghxh").toString(),tempMoney);
		money += (num * price);
	}
	
	for(Map map : feelist){
		
		double price = Double.parseDouble(map.get("xmje").toString());
		double tempMoney = moneyMap.get(map.get("ghxh").toString()) == null ? 0 : Double.parseDouble(moneyMap.get(map.get("ghxh").toString()).toString());
		
	
		tempMoney +=price;
		
		moneyMap.put(map.get("ghxh"),(tempMoney));
		
		money += price;
	}
	
	//处理最后的集合
	for(Map map : list){
		map.put("zdmc",zdMap.get(map.get("ghxh")) == null ? "" : zdMap.get(map.get("ghxh")));
		
		map.put("money",moneyMap.get(map.get("ghxh").toString()) );
		
	}
	Message msg = new Message();
	msg.put("errcode",0);
	msg.put("data",list);
	msg.put("money",money);
	out.println(msg);
%>